package com.wx.session;

public class SessionThread implements Runnable {

	private String openid;

	public SessionThread(String openid) {
		this.openid = openid;
	}

	public void run() {
		// while(SessionList.sleep()) {
		while (true) {
			System.out.println("计时线程启动");
			if (SessionList.search(openid) >= 0) {
				try {
					// 休眠1分钟
					System.out.println("开始休眠");
					Thread.sleep(60 * 1000);
					System.out.println("已休眠一分钟,");
					if (SessionList.search(openid) >= 0) {
						if (!SessionList.timeStop(openid)) {
							SessionList.timeMin(openid); // 每隔60秒苏醒一次，将计时器减60秒
						}
						if (SessionList.timeStop(openid)) { // 如果计时器为零
							SessionList.remove(openid); // 删除session
							System.out.println("删除session");
						}
						System.out.println("剩余时间： " + SessionList.getTime(openid) / 1000 + "秒");
					}
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			} else {
				break;
			}
		}
		System.out.println("计时线程结束");

	}

}
